<?php





/**
 * 
 * PHP Module Creator
 * @version $Id: phpmc.php,v 1.21 2005/01/15 17:04:36 phppc Exp $
 * @copyright 2003 
 **/
 
class phpmc{
	/**
     * Constructor
     * @access protected
     */
	var $config = array(); // Array with all configuration infos (DB-Host, DB-Username, etc.)
	var $libs = array(); // Array with all libs that will be included
	var $module_intern_array = array(); // Array with all set module points
	var $module_standard_value = array(); // Standard value of a module
	var $module_new_value = array(); // Array with the new values of a module (used for hidden values (in a form) and links)
	var $module_config = array(); // Array with some module config vars
	var $loaded_libs = array(); // Array with the name of all loaded libs
	var $w_leitung = array(); // Array with all information needed
	var $message_green = array(); // Array with all positive messages (Standard-Color: green)
	var $message_red = array(); // Array with all negative messages (Standard-Color: red)
	var $nc_main = ""; // main part of the template (mostly it's the content of the main module)
	var $main_abfrage = ""; // main sql query
	var $mgreen = ""; // xhtml code of all green messages
	var $mred = ""; // xhtml code of all red messages
	var $weiterleitung = ""; // xhtml code of all forwarding messages
	var $weiterleitung_meta = ""; // xhtml code of the forwarding tool
	var $ncs = ""; // Session variable
	var $needed_time = 0; // time needed for creating the site
	
	/**
	 *
	 * @access public
	 * @return void
	 **/
	function set_config($config_file){ // Includes the config file and sets the config array
		include $config_file;      
	}
	
	 
	/**
	 *
	 * @access public
	 * @return void 
	 **/
	function set_module_point($module_intern, $restrict_array, $standard_value, $extern_name = ""){ // Sets a module point 
		$this->module_intern_array[$module_intern] = $restrict_array;
		$this->module_standard_value[$module_intern] = $standard_value;
		if($extern_name != "") $this->module_extern_array[$module_intern] = $extern_name;
	}
	
	/**
	 * phpmc::add_restrict_values()
	 * 
	 * @param $module_intern
	 * @param array $new_restrict
	 * @return 
	 **/
	function add_restrict_values($module_intern, $new_restrict = array()) {
		$module_intern_array[$module_intern] = array_merge($module_intern_array[$module_intern],$new_restrict);
	}
	
	/**
	 * phpmc::load_libs()
	 * 
	 * @param $libs_array
	 * @return 
	 **/
	function load_libs($libs_array){ // Includes all libraries (classes, functions) that are set by $libs_array
		foreach ($libs_array as $file_name) {
			include $this->config["a_pfad"] . $this->config["sub_dir_lib"] . $this->config["lib_before"] . $file_name . $this->config["lib_endung"];
		}
		$this->fun_check_speed();
		$this->loaded_libs = $libs_array;
	}
	
	/**
	 * phpmc::load_module()
	 * 
	 * @param $module_name
	 * @param $module_intern
	 * @return 
	 **/
	function load_module($module_name, $module_intern) {
		$nc_main = "";
		include $this->config["a_pfad"] . $this->config["sub_dir_inc"] . $module_name . $this->config["inc_endung"];
		$this->inc_value["$module_intern"] = $nc_main;
	}
	
	/**
	 * phpmc::set_components()
	 * 
	 * @param $comp_array
	 * @param integer $kind
	 * @return 
	 **/
	function set_components($comp_array,$kind = 1){ // 
		$array_name = "comp" . $kind . "_array";
		$this->$array_name = $comp_array;
	}
	
	
	/**
	 * phpmc::load_components()
	 * 
	 * @param integer $kind
	 * @return 
	 * @desc Loads components of a certain kind set by set_components()
	 **/
	function load_components($kind = 1){
		$array_name = "comp" . $kind . "_array";
		$comp_array = $this->$array_name;
		if(is_array($comp_array)) {
			foreach ($comp_array as $component) {
				$this->fun_check_speed($component,0);
				include $this->config["a_pfad"] . $this->config["sub_dir_comp"] . $component . ".inc.php";
				$this->fun_check_speed($component,1);
			}
		}
	}
	
	/**
	 * phpmc::output()
	 * 
	 * @param string $main_tpl
	 * @param string $main_tpl_dir
	 * @return 
	 **/
	function output($main_tpl = "news", $main_tpl_dir = ""){ 
		$this->load_components(1); // First loading of certain components
		// Loading modules
		foreach ($this->module_intern_array as $module_intern => $restrict_array) { // The value of the var $module_name is the file name
			$this->$module_intern = $this->fun_sg2var($this->module_extern_array[$module_intern]);
			$standard_value = $this->module_standard_value[$module_intern];
			$this->$module_intern = $this->uf_form_conf_def($this->$module_intern, $restrict_array, $standard_value);
			$this->fun_check_speed($module_intern,0);
			$this->load_module($this->$module_intern, $module_intern);
			$this->fun_check_speed($module_intern,1);
		}
		$this->load_components(2); // Second loading of certain components

		$this->tpl_load($main_tpl,$main_tpl_dir);
		if(!empty($this->main_replace_vars))$this->tpl_replace_vars($this->main_replace_vars);
		return $this->tpl_output();
	}
}


?>